<template>
  <el-container>
    <!-- <el-header>Header</el-header> -->
    <el-main v-if="tableData">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column fixed prop="bookid" label="账号编号" width="150">
        </el-table-column>
        <el-table-column prop="id" label="租借编号" width="200">
        </el-table-column>
        <el-table-column prop="bookName" label="账号" width="200">
        </el-table-column>
        <el-table-column prop="sreturn" label="状态" width="120">
        </el-table-column>
        <el-table-column prop="starttime" label="租借时间" width="120">
        </el-table-column>
        <el-table-column prop="opentime" label="审核时间" width="120">
        </el-table-column>
        <el-table-column prop="endtime" label="归还时间" width="120">
        </el-table-column>
        <el-table-column prop="userName" label="租借人" width="120">
        </el-table-column>
        <el-table-column prop="price" label="金额" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row, 1)"
              type="text"
              size="small"
              >借出</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: "MyRegistration",
  methods: {
    getLocalTime(time) {
      var date = new Date(parseInt(time));
      var year = date.getFullYear();
      var mon = date.getMonth() + 1;
      var day = date.getDate();
      return year + "/" + mon + "/" + day;
    },
    handleClick(row, state) {
      this.$axios
        .post(`${this.url}/book/serreturn`, {
          id: row.id,
          state,
        })
        .then(() => this.getdata());
    },
    getdata() {
      this.$axios.get(`${this.url}/book/getlist`).then((content) => {
        console.log(content.data.data);
        let arr = [];
        content.data.data.forEach((item) => {
          item.starttime = this.getLocalTime(item.starttime - 0);
          item.endtime =
            item.endtime == null ? "" : this.getLocalTime(item.endtime);
          item.opentime =
            item.opentime == null ? "" : this.getLocalTime(item.opentime);
          if (item.sreturn == 0) {
            item.sreturn = "待审核";
          } else if (item.sreturn == 1) {
            item.sreturn = "待归还";
          } else if (item.sreturn == 2) {
            item.sreturn = "已归还";
          }
          arr.push(item);
        });

        this.tableData = arr;
      });
    },
  },
  created() {
    this.getdata();
  },
  data() {
    return {
      tableData: null,
      url: "http://192.168.35.36:3005",
    };
  },
};
</script>

<style lang="less" scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
</style>